/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} k
 * @return {number}
 */
var kthLargest = function(root, k) {
  let nodeArr = [];
  function preView(node) {
    if(!node) return;
    nodeArr.push(node.val);
    preView(node.left);
    preView(node.right);
  }
  preView(root);
  nodeArr.sort((a, b) => b - a);
  return nodeArr[k - 1];
};
